package com.yystar.support.interfaceaccess.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.yystar.support.clock.service.ClockService;
import com.yystar.support.interfaceaccess.InterfaceAccess;
import com.yystar.support.interfaceaccess.InterfaceAccessDao;
import com.yystar.support.interfaceaccess.InterfaceAccessService;

@Service
public class InterfaceAccessServiceImpl implements InterfaceAccessService {
	@Resource
	private InterfaceAccessDao interfaceAccessDao;
	@Resource
	private ClockService clockService;

	public boolean canAccess(String ipAddr) {
		List<InterfaceAccess> accessList = interfaceAccessDao.getUnexpriedAccess(ipAddr);
		for (InterfaceAccess access : accessList) {
			if (access.getExpiryDateTime().after(clockService.getCurrentDatabaseDateTime())) {
				return true;
			}
		}
		return false;
	}
}
